<template>
    <div class="container">
        <Header :infoList="infoList"></Header>
        <van-search
            v-model="value"
            show-action
            placeholder="院校信息，留学资讯，一手掌握"
            @search="onSearch"
        >
            <template #action>
                <div @click="onSearch">搜索</div>
            </template>
        </van-search>
        <van-tabs v-model="active" >
            <van-tab>
                <div slot="title">全部</div>
                <div class="tab_content">
                    <van-loading v-if="loading" size="24px" vertical>加载中...</van-loading>
                    <div class="conten_module">
                        <div class="title_">相关学校</div>
                        <a  v-for="(univer, uindex) in searchData.university" :key="uindex" class="school" @click="collegeInfo(univer.id)">
                            <div class="school-logo">
                                <img :src="getImgUrl(univer.thumb)" alt="" class="school-logo--img" >
                            </div>
                            <div class="school-content">
                                <h2 class="school-content--title"><span><span >{{univer.title}}</span></span></h2>
                                <div class="school-content--desc">{{univer.sort_title}}</div>
                            </div><i style="position: absolute;  right: 5%;top: 40%;">></i>
                        </a>


                        <div
                            class="load-more-btn"
                            @click="linToMoreSchool(1)"
                        >
                            <div
                                role="button"
                                tabindex="0"
                                class="mobile search-btn"
                            >查看更多相关学校</div>
                        </div>
                    </div>
                    <div class="conten_module">
                        <div class="title_">相关留学资讯</div>
                        <div class=" view-content">

                            <div class=" view-list">

                                <a href="javascript:;" class=" item-content"  v-for="(article, aindex) in searchData.information" @click="goToDetail(article.id)" :key="aindex">
                                    <div
                                            class=" item-bg"
                                            :style="{'background-image': 'url('+getImgUrl(article.thumb)+')'}"
                                    ></div>
                                    <div class=" item-title">
                                        {{article.title}}
                                    </div>
                                    <div class=" item-intro">
                                        <div class=" item-tag"> {{article.tags}}</div>
                                        <div class=" item-time"> {{article.add_time | formatDate}}</div>
                                    </div>
                                </a>
                            </div>
                        </div>
                        <div
                                class="load-more-btn"
                                @click="linToMoreSchool(2)"
                        >
                            <div
                                    role="button"
                                    tabindex="0"
                                    class="mobile search-btn"
                            >查看更多相关留学资讯</div>
                        </div>
                    </div>
                </div>
            </van-tab>
            <van-tab>
                <div slot="title">学校</div>
                <div class="tab_content">
                    <van-loading v-if="loading" size="24px" vertical>加载中...</van-loading>
                    <div class="conten_module">
                        <a  v-for="(univer, uindex) in universityList" :key="uindex" class="school"  @click="collegeInfo(univer.id)">
                            <div class="school-logo">
                                <img :src="getImgUrl(univer.thumb)" alt="" class="school-logo--img" >
                            </div>
                            <div class="school-content">
                                <h2 class="school-content--title"><span><span >{{univer.title}}</span></span></h2>
                                <div class="school-content--desc">{{univer.sort_title}}</div>
                            </div><i style="position: absolute;  right: 5%;top: 40%;">></i>
                        </a>
                    </div>
                </div>
            </van-tab>

            <van-tab>
                <div slot="title">留学资讯</div>
                <div class="tab_content">
                    <div class=" view-content">

                    <div class=" view-list">

                        <a href="javascript:;" class=" item-content"  v-for="(article, aindex) in searchData.information" @click="goToDetail(article.id)" :key="aindex">
                            <div
                                    class=" item-bg"
                                    :style="{'background-image': 'url('+getImgUrl(article.thumb)+')'}"
                            ></div>
                            <div class=" item-title">
                                {{article.title}}
                            </div>
                            <div class=" item-intro">
                                <div class=" item-tag"> {{article.tags}}</div>
                                <div class=" item-time"> {{article.add_time | formatDate}}</div>
                            </div>
                        </a>
                    </div>
                    </div>
                </div>
            </van-tab>
        </van-tabs>
    </div>
</template>

<script>
import Header from "./../header/Header.vue";
import {search,getUniversity} from './../../service/index.js';
export default {
  name: "Search",
    components: {
        Header,
    },
  data() {
    return {
      value: "",
      active: 0,
        universityList:[],
      searchData:{
          university:[],
          information:[],
      },
      loading:true,
    };
  },

  created() {
    this.value = this.$route.params.searchValue;
    this.onSearch();
      getUniversity().then((res)=>{
          console.log(res);
          this.universityList = res.data.university_list
      }).catch(err=>{
          console.log(err)
      })
  },
  methods: {
    onSearch() {
      let value = this.value==undefined ? '' : this.value;
        let params = {value:value};
        search(params).then(response=>{
            if(response.code == 200){
              this.searchData.university = response.data.university;
              this.searchData.information = response.data.information;
                console.log(this.searchData.information);
                this.loading = false;
            }

        }).catch(err=>{
            console.log(err )
        })
    },

    linToMoreSchool(index) {
        // console.log(index)
      this.active = index;
    },
      goToDetail(id){
          console.log(id);
          this.$router.push({path:"/newsDetail?id="+id,query:{id:id}});
      },
      collegeInfo(id){
          this.$router.push({path:'/collegeItemIntru',query:{id:id}})
      },
  },
};
</script>

<style lang="less">
    .van-tabs__nav{
        text-align: center;
    }
    .view-content {
        padding: .28rem 0.75rem 0px;
    }
    .view-list {
        width: 100%;
        overflow: hidden;
        padding-bottom: 1.375rem;
    }

    .item-content {
        display: block;
        cursor: pointer;
        padding-bottom: 0.55rem;
        margin-bottom: 0.55rem;
        border-bottom: 1px solid rgb(236, 236, 236);
    }

    .item-content .item-bg {
        flex: 0 0 42.5%;
        height: 7.375rem;
        background-position: center center;
        background-size: cover;
        background-repeat: no-repeat;
        border-radius: 2.5px;
        box-shadow: rgba(0, 0, 0, 0.1) 0px 2.5px 5px 0px;
    }

    .item-content .item-title {
        color: rgb(42, 65, 84);
        font-size: 0.8rem;
        padding: 0.4rem 0px;
        overflow: hidden;
        text-overflow: ellipsis;
        overflow-wrap: break-word;
        word-break: break-all;
        text-align: justify;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 3;
        display: -webkit-box !important;
    }

    .item-content .item-intro {
        display: flex;
        -webkit-box-pack: justify;
        justify-content: space-between;
    }

    .item-content .item-tag {
        border-radius: 0.125rem;
        border: 1px solid rgb(0, 164, 255);
        background-color: rgb(239, 249, 255);
        color: rgb(38, 171, 255);
        font-size: 0.5rem;
        line-height: 0.8rem;
        letter-spacing: 0.01px;
        padding: 0.05rem 0.125rem;
    }

    .item-content .item-time {
        text-align: left;
        color: rgb(115, 116, 116);
        font-size: 0.7rem;
        display: flex;
        -webkit-box-align: center;
        align-items: center;
    }
.title_ {
  font-size: 0.875rem;
  color: rgb(42, 65, 84);
  margin-top: 1.2rem;
  margin-bottom: 0.45rem;
    padding-left: 1rem;
}
.school {
  display: flex;
  padding: 1rem 0.675rem 1rem 1rem;
  border-bottom: 1px solid rgb(234, 234, 234);
    position: relative;
}
.school-logo {
  height: 4.25rem;
  display: flex;
  -webkit-box-align: center;
  align-items: center;
  -webkit-box-pack: start;
  justify-content: flex-start;
  flex: 0 0 3.925rem;
}
.school-logo--img {
  max-width: 2.9rem;
  max-height: 3.125rem;
  display: block;
}
.school-content {
  display: flex;
  flex-direction: column;
  -webkit-box-pack: center;
  justify-content: center;
  flex: 1 1 0%;
}
h2 {
  display: block;
  font-size: 1.5em;
  margin-block-start: 0.83em;
  margin-block-end: 0.83em;
  margin-inline-start: 0px;
  margin-inline-end: 0px;
  font-weight: bold;
}
.school-content--title {
  font-size: 0.8rem;
  color: rgb(42, 65, 84);
}
.school-content--desc {
  margin-top: 0.2rem;
  font-size: 0.5rem;
  color: rgb(149, 149, 149);
}
.school-content-major {
  margin-top: 0.25rem;
}
.school-content-major--label {
  font-size: 0.5rem;
  color: rgb(152, 152, 152);
  line-height: 1.6;
}
.school-content-major--value {
  font-size: 0.6rem;
  color: rgb(113, 113, 113);
  line-height: 1.6;
}
.school-content-degree {
  display: flex;
  margin-top: 0.25rem;
}
.school-content-degree--label {
  color: rgb(0, 164, 255);
  font-size: 0.6rem;
  display: flex;
  -webkit-box-align: center;
  align-items: center;
}
.load-more-btn {
  text-align: center;
  margin-top: 0.875rem;
  margin-bottom: 0.5rem;
}
.mobile.search-btn {
  color: rgb(0, 164, 255);
  cursor: pointer;
  display: inline-block;
  font-size: 0.6rem;
  line-height: 0.6rem;
  text-align: center;
  border-width: 1px;
  border-style: solid;
  border-color: rgb(0, 164, 255);
  border-image: initial;
  padding: 0.55rem 1.5rem;
  border-radius: 0.85rem;
  transition: all 0.3s ease 0s;
  outline: 0px;
}
.major{
    padding: 0.75rem 0px 1rem;
    border-bottom: 1px solid rgb(234, 234, 234);
}
.major-title{
    display: flex;
    -webkit-box-align: center;
    align-items: center;
    color: rgb(42, 65, 84);
    font-size: 0.6rem;
    margin-bottom: 0.75rem;
}
.major-title--logo{
    display: flex;
    -webkit-box-align: center;
    align-items: center;
    -webkit-box-pack: start;
    justify-content: flex-start;
    flex: 0 0 1.6rem;
}
.major-title--logo--img{
    max-width: 1.25rem;
    max-height: 1.35rem;
    display: block;
}
.major-content--name{
    font-size: 0.8rem;
    color: rgb(42, 65, 84);
    margin-bottom: 0.2rem;
}

h3 {
    display: block;
    font-size: 1.17em;
    margin-block-start: 1em;
    margin-block-end: 1em;
    margin-inline-start: 0px;
    margin-inline-end: 0px;
    font-weight: bold;
}
.major-content--desc{
    color: rgb(149, 149, 149);
    font-size: 0.6rem;
}
</style>
